home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Caml Light 0.7 / Caml Light 0.7 source / src / lex / scan_aux.ml < prev    next >
Text File  |  1995-06-19  |  1KB  |  48 lines

  1. (* Auxiliaries for the lexical analyzer *)
  2.  
  3. #open "lexing";;
  4.  
  5. let brace_depth = ref 0
  6. and comment_depth = ref 0;;
  7.  
  8. exception Lexical_error of string;;
  9.  
  10. let initial_string_buffer = create_string 256;;
  11. let string_buff = ref initial_string_buffer;;
  12. let string_index = ref 0;;
  13.  
  14. let reset_string_buffer () =
  15.   string_buff := initial_string_buffer;
  16.   string_index := 0
  17. ;;
  18.  
  19. let store_string_char c =
  20.   (if !string_index >= string_length (!string_buff) then
  21.     let new_buff = create_string (string_length (!string_buff) * 2) in
  22.       blit_string new_buff 0 (!string_buff) 0 (string_length (!string_buff));
  23.       string_buff := new_buff;
  24.       ());
  25.   set_nth_char (!string_buff) (!string_index) c;
  26.   incr string_index
  27. ;;
  28.  
  29. let get_stored_string () =
  30.   let s = sub_string (!string_buff) 0 (!string_index) in
  31.     string_buff := initial_string_buffer;
  32.     s
  33. ;;
  34.  
  35. let char_for_backslash = function
  36.     `n` -> `\n`  (* do NOT put explicit numeric values here -- DD *)
  37.   | `t` -> `\t`
  38.   | `b` -> `\b`
  39.   | `r` -> `\r`
  40.   | c   -> c
  41. ;;
  42.  
  43. let char_for_decimal_code lexbuf i =
  44.   char_of_int(100 * (int_of_char(get_lexeme_char lexbuf i) - 48) +
  45.                10 * (int_of_char(get_lexeme_char lexbuf (i+1)) - 48) +
  46.                     (int_of_char(get_lexeme_char lexbuf (i+2)) - 48))
  47. ;;
  48.